BIQUADQ31.cpp 3.9 KB

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