BIQUADQ31.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "BIQUADQ31.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 115
  5. #define ABS_ERROR_Q31 ((q31_t)1000)
  6. #define SNR_32x64_THRESHOLD 140
  7. #define ABS_32x64_ERROR_Q31 ((q31_t)25)
  8. static void checkInnerTail(q31_t *b)
  9. {
  10. ASSERT_TRUE(b[0] == 0);
  11. ASSERT_TRUE(b[1] == 0);
  12. ASSERT_TRUE(b[2] == 0);
  13. ASSERT_TRUE(b[3] == 0);
  14. }
  15. void BIQUADQ31::test_biquad_cascade_df1()
  16. {
  17. q31_t *statep = state.ptr();
  18. const q31_t *coefsp = coefs.ptr();
  19. const q31_t *inputp = inputs.ptr();
  20. q31_t *outp = output.ptr();
  21. int blockSize;
  22. /*
  23. Python script is generating different tests with
  24. different blockSize and numTaps.
  25. We loop on those configs.
  26. */
  27. blockSize = inputs.nbSamples() >> 1;
  28. /*
  29. The filter is initialized with the coefs, blockSize and numTaps.
  30. */
  31. arm_biquad_cascade_df1_init_q31(&this->S,3,coefsp,statep,2);
  32. /*
  33. Python script is filtering a 2*blockSize number of samples.
  34. We do the same filtering in two pass to check (indirectly that
  35. the state management of the fir is working.)
  36. */
  37. arm_biquad_cascade_df1_q31(&this->S,inputp,outp,blockSize);
  38. outp += blockSize;
  39. inputp += blockSize;
  40. arm_biquad_cascade_df1_q31(&this->S,inputp,outp,blockSize);
  41. outp += blockSize;
  42. ASSERT_EMPTY_TAIL(output);
  43. ASSERT_SNR(output,ref,(q31_t)SNR_THRESHOLD);
  44. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31);
  45. }
  46. void BIQUADQ31::test_biquad_cascade_df1_32x64()
  47. {
  48. q63_t *statep = state64.ptr();
  49. const q31_t *coefsp = coefs.ptr();
  50. q31_t *inputp = inputs.ptr();
  51. q31_t *outp = output.ptr();
  52. int blockSize;
  53. /*
  54. Python script is generating different tests with
  55. different blockSize and numTaps.
  56. We loop on those configs.
  57. */
  58. blockSize = inputs.nbSamples() >> 1;
  59. /*
  60. The filter is initialized with the coefs, blockSize and numTaps.
  61. */
  62. arm_biquad_cas_df1_32x64_init_q31(&this->S32x64,3,coefsp,statep,2);
  63. /*
  64. Python script is filtering a 2*blockSize number of samples.
  65. We do the same filtering in two pass to check (indirectly that
  66. the state management of the fir is working.)
  67. */
  68. #if 0
  69. arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
  70. outp += blockSize;
  71. inputp += blockSize;
  72. arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
  73. outp += blockSize;
  74. #else
  75. int delta=1;
  76. int k;
  77. for(k=0;k + delta <2*blockSize ; k+=delta)
  78. {
  79. arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
  80. outp += delta;
  81. checkInnerTail(outp);
  82. inputp += delta;
  83. }
  84. if (k < 2*blockSize)
  85. {
  86. delta = 2*blockSize - k;
  87. arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
  88. outp += delta;
  89. checkInnerTail(outp);
  90. inputp += delta;
  91. }
  92. #endif
  93. ASSERT_EMPTY_TAIL(output);
  94. ASSERT_SNR(output,ref,(q31_t)SNR_32x64_THRESHOLD);
  95. ASSERT_NEAR_EQ(output,ref,ABS_32x64_ERROR_Q31);
  96. }
  97. void BIQUADQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  98. {
  99. (void)params;
  100. switch(id)
  101. {
  102. case BIQUADQ31::TEST_BIQUAD_CASCADE_DF1_1:
  103. /* max 4 * nbTaps as generated by Python script */
  104. /* Same OUTID is reused. So linked to same output file. If it is dumped
  105. it may overwrite the output
  106. */
  107. state.create(32,BIQUADQ31::OUT_Q31_ID,mgr);
  108. break;
  109. case BIQUADQ31::TEST_BIQUAD_CASCADE_DF1_32X64_2:
  110. state64.create(32,BIQUADQ31::STATE_Q64_ID,mgr);
  111. break;
  112. }
  113. inputs.reload(BIQUADQ31::BIQUADINPUTS_Q31_ID,mgr);
  114. coefs.reload(BIQUADQ31::BIQUADCOEFS_Q31_ID,mgr);
  115. ref.reload(BIQUADQ31::BIQUADREFS_Q31_ID,mgr);
  116. output.create(ref.nbSamples(),BIQUADQ31::OUT_Q31_ID,mgr);
  117. }
  118. void BIQUADQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  119. {
  120. (void)id;
  121. output.dump(mgr);
  122. }